/********************************************************************
    Rhapsody	: 8.0.4
    Login		: Administrator
    Component	: ServerRun
    Configuration 	: TestConfig
    Model Element	: TestConfig
//!	Generated Date	: Thu, 12, Jul 2018  
    File Path	: ../../ServerRun/main.cpp
*********************************************************************/

#include <oxf.h>
#include <iostream>
#include <signal.h>
#include <unistd.h>
#include "FPM_Server.h"

static bool finished = false;

static void
signalHandler(int signo) {
    std::cerr << "Shutting down" << std::endl;
    finished = true;
}

int main(int argc, char* argv[]) {
	int status = 0;
	if (OXF::getInstance()->initialize(0,0)) {
		// Install signal handlers
		//OXF::start(true);
#ifndef _WIN32
		if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
			std::cerr << "Couldn't install signal handler for SIGPIPE" << std::endl;
			exit(-1);
		}
		//        if ( signal( SIGHUP,signalHandler ) == SIG_ERR )
		//        {
		//            std::cerr << "Couldn't install signal handler for SIGHUP" << std::endl;
		//            exit( -1 );
		//        }
#endif
		if (signal(SIGINT, signalHandler) == SIG_ERR) {
			std::cerr << "Couldn't install signal handler for SIGINT" << std::endl;
			exit( -1 );
		}
		if (signal(SIGTERM, signalHandler) == SIG_ERR) {
			std::cerr << "Couldn't install signal handler for SIGTERM" << std::endl;
			exit( -1 );
		}

		iLPR_Server* server = new iLPR_Server();
		server->init();
		if(!server->run()){
			std::cerr << "Failed to start iLPR, exiting..." << std::endl;
			delete server;
			exit(-1);
		}
		printf("\nserver start\n");
		//#]

		while (!finished) {
#ifdef WIN32
			Sleep(1000);
#else
			usleep(1000*1000);
#endif
		}
		delete server;
		exit(status);
		status = 0;
	} else {
		status = 1;
	}
	return status;
}

/*********************************************************************
  File Path	: ../../RunServer/main.cpp
 *********************************************************************/
